package com.czb.dao;

import com.czb.bean.House;
import com.czb.bean.User;
import com.czb.util.DBHelper;
import com.czb.util.PageBean;

import java.util.List;
import java.util.Map;

public class UserDao {
    public Map login(String sql, Object[] objects) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        Map map = dbHelper.showById(sql, objects);
        if(map != null) {
            return map;
        }else {
            return null;
        }
    }

    public PageBean<Map> pageList(int page, int limit, String sql,Object ... obj) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        PageBean<Map> pagelist = dbHelper.pageList(page, limit, sql,obj);
        return  pagelist;
    }


    public List<Map> contrAll(String sql, Object o) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        List<Map> list = dbHelper.select(sql);
        return list;
    }

    public List<Map> userAll(String sql) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        List<Map> list = dbHelper.select(sql);
        return list;
    }

    public int addHouse(String sql, Object[] objects) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        int i = dbHelper.update(sql, objects);
        return i;
    }

    public List<Map> toAddLess(String sql) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        List<Map> list = dbHelper.select(sql);
        return list;
    }

    public List<Map> toAddHouse(String sql) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        List<Map> list = dbHelper.select(sql);
        return list;
    }

    public int toAdd(String sql, Object[] obj) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        int i = dbHelper.update(sql, obj);
        return i;
    }

    public Map showId(String sql, Integer h_id) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        Map map = dbHelper.showById(sql, h_id);
        return map;
    }

    public int updateHouse(String sql, Object[] objects) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        int i = dbHelper.update(sql, objects);
        return i;
    }

    public Map shId(String sql, Integer c_id) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        Map map = dbHelper.showById(sql, c_id);
        return map;
    }

    public int update(String sql, Object[] obj) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        int i = dbHelper.update(sql, obj);
        return i;
    }

    public int delete(String sql, Integer h_id) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        int i = dbHelper.update(sql, h_id);
        return i;
    }

    public int del(String sql, Integer c_id) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        int i = dbHelper.update(sql, c_id);
        return i;
    }



    public List<Map> showName(String sql, Integer l_id) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        List<Map> list = dbHelper.select(sql,l_id);
        return list;
    }


    public int userAdd(String sql, Object[] obj) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        int i = dbHelper.update(sql, obj);
        return i;
    }

    public Map showById(String sql, Integer u_id) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        Map map = dbHelper.showById(sql, u_id);
        return map;
    }

    public int deId(String sql, Integer u_id) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        int i = dbHelper.update(sql, u_id);
        return i;
    }

    public int userUpdate(String sql, Object[] obj) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        int i = dbHelper.update(sql, obj);
        return i;
    }

    public PageBean<Map> pageList(int page, int pageSize, String sql) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        PageBean<Map> pagelist = dbHelper.pageList(page, pageSize, sql);
        return  pagelist;
    }
}
